﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Schedule : System.Web.UI.Page
{
    string tid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        tid = Request.Params["tid"].ToString();
        if (!IsPostBack)
        {
           //Session["TourgroupID"] = Request.Params["tid"].ToString();
            
            if (!string.IsNullOrEmpty(tid))
            {
                //GuestInfoInit(Session["TourgroupID"].ToString());
                //ChangeNotifyInfoInit(Session["TourgroupID"].ToString());
                //GuideStatusInfoInit(Session["TourgroupID"].ToString());
                BaseInfoInit(tid);
            }
            else//处理导游ID,用于双击导游安排显示团详细信息
            {
                //string cid = Request.Params["cid"].ToString();
                //string filterExpression = string.Format("CiceroniID={0}", cid);
                //DataRow[] drs = _dtGuideArrangeInfo.Select(filterExpression);
                //if (drs.Length > 0)
                //    new GuideStatusLookupTourgroup(drs).ShowDialog(this);
            }
        }
    }
    protected void btnGuest_Click(object sender, EventArgs e)
    {
        guestListGridView.DataSource = TeamGroupCtrl.GetGuestListData(Request.Params["tid"].ToString());
        guestListGridView.DataBind();
        string url = string.Format("Schedule/GuestInfo.aspx?tid={0}", tid);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "guestinfo", string.Format("<script>OpenPopWindows('{0}','客户信息',1);</script>", url));
        //Page.ClientScript.RegisterStartupScript(this.GetType(), "guestinfo", string.Format("<script>openwindow('{0}','客户信息',800,150);</script>", url));
    }
    protected void btnGuide_Click(object sender, EventArgs e)
    {
        guideListGridView.DataSource = GuideArrangeCtrl.GetGuideArrangeData(Request.Params["tid"].ToString());
        guideListGridView.DataBind();
        string url = string.Format("Schedule/GuideInfo.aspx?tid={0}", tid);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "guideinfo", string.Format("<script>OpenPopWindows('{0}','导游信息',2);</script>", url));
        //Page.ClientScript.RegisterStartupScript(this.GetType(), "guestinfo", string.Format("<script>openwindow('{0}','导游信息',700,150);</script>", url));
    }
    protected void btnNotify_Click(object sender, EventArgs e)
    {
        changeNotifyGridView.DataSource = BaseInfoCtrl.GetChangeNotifyData(Request.Params["tid"].ToString());
        changeNotifyGridView.DataBind(); 
        string url = string.Format("Schedule/NotifyInfo.aspx?tid={0}", tid);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "notifyinfo", string.Format("<script>OpenPopWindows('{0}','通知信息',3);</script>", url));
        //Page.ClientScript.RegisterStartupScript(this.GetType(), "guestinfo", string.Format("<script>openwindow('{0}','通知信息',700,150);</script>", url));
    }

    private void BaseInfoInit(string tourgroupid)
    {
        //团状态信息
        DataTable teamRowData = TeamGroupCtrl.GetTeamGroupRowData(tourgroupid);
        lblTourGroupID.Text=teamRowData.Rows[0]["TourgroupID"].ToString();
        lblTourGroupState.Text = teamRowData.Rows[0]["TourgroupState"].ToString();

        tbCountry.Text = teamRowData.Rows[0]["Country"].ToString();
        lblCountryCode.Text = teamRowData.Rows[0]["CountryCode"].ToString();
        tbStartDate.Text = teamRowData.Rows[0]["StartDate"].ToString();
        tbEndDate.Text = teamRowData.Rows[0]["EndDate"].ToString();
        tbNightNum.Text = teamRowData.Rows[0]["StayOver"].ToString();
        tbAdultNum.Text = teamRowData.Rows[0]["AdultNum"].ToString();
        tbChildNum.Text = teamRowData.Rows[0]["ChildNum"].ToString();
        tbTourgroupName.Text = teamRowData.Rows[0]["TourgroupName"].ToString(); 
        cbGuesttype.Text = teamRowData.Rows[0]["Guesttype"].ToString();
        cbServicetype.Text = teamRowData.Rows[0]["Servicetype"].ToString(); 
        cbTourgrouptype.Text = teamRowData.Rows[0]["Tourgrouptype"].ToString();
        tbAccompanyNum.Text = teamRowData.Rows[0]["AccompanyNum"].ToString(); 
        tbCustomerCode.Text = teamRowData.Rows[0]["CustomerCode"].ToString(); 
        lblCustomerName.Text = teamRowData.Rows[0]["CustomerName"].ToString(); 
        cbOwnerA.Text = teamRowData.Rows[0]["OwnerA"].ToString(); 
        cbOwnerB.Text = teamRowData.Rows[0]["OwnerB"].ToString();
        ckHasGuide.Checked = bool.Parse(teamRowData.Rows[0]["HasGuide"].ToString());
        tbBuildGroupDate.Text = teamRowData.Rows[0]["BuildGroupDate"].ToString();
        mbRemark.Text = teamRowData.Rows[0]["Remark"].ToString();


        ScheduleGridView.DataSource = TeamGroupCtrl.GetTourGroupSchedule(tourgroupid).Tables[0];// new DataView();
        ScheduleGridView.DataBind();
    }


}